<template>
    <!-- 抬头 -->
    <PageTitle :classify="classify" />

    <!-- 搜索 -->
    <van-search v-model="value" placeholder="请输入搜索关键词" shape="round" class="search" />

    <!-- 分割线 -->
    <hr>

    <!-- 问诊记录 -->
    <div class="histry">
        <span>上一次问诊记录</span>
        <img src="@/assets/images/aboutDoctorPage/rightHaircat.png">
    </div>

    <!-- 内容区 -->
    <div class="content">
        <!-- 左侧目录导航栏 -->
        <div class="left-catalogue">
            <div class="catalogue" v-for="(item, index) in catalogue" :key="index" @click="onClickImg(index)">
                <div class="catalogue-title" :class="{ selected: currentIndex === index }">
                    <span>{{ item }}</span>
                </div>
            </div>
        </div>
        <!-- 右侧疾病属类 -->
        <div class="right-content">
            <DataContent :infoData="infoData" />
        </div>
    </div>
</template>

<script>
import { ref, onUnmounted, watch } from 'vue';
import PageTitle from '@/components/pageTitle/pageTitle.vue';
import DataContent from './components/doctorConsultation_content.vue';
import { getCatalogueData } from './api/index';
import { showToast } from 'vant';

export default {
    components: {
        PageTitle,
        DataContent,
    },
    setup() {
        const classify = ref('医师问诊');
        const value = ref('');
        const catalogue = ref([
            '宠物科'
        ]);
        const currentIndex = ref(0);
        const info = ref(1);  // 当前选中的导航栏
        const infoData = ref([]); // 获取数据

        // 获取数据
        watch(
            info,
            (newVal, oldVal) => {
                console.log(`info changed from ${oldVal} to ${newVal}`);
                getCatalogueData({
                    id: newVal,
                }).then(
                    (res) => {
                        if (res && res.code === 200) {
                            console.log('Response:', res);
                            if (res.data && Array.isArray(res.data)) {
                                infoData.value = res.data;
                                console.log(infoData.value);
                            } else {
                                showToast('数据格式错误');
                            }
                        } else {
                            showToast('获取数据失败');
                        }
                    },
                    (error) => {
                        showToast('请求失败');
                        console.error('错误:', error);
                    }
                );
            },
            { immediate: true }
        );

        const onClickImg = (index) => {
            info.value = index + 1;
            currentIndex.value = index;
            console.log(info.value, "kkk");
        };

        onUnmounted(() => {
            console.log('组件销毁了');
        });

        return {
            onClickImg,
            classify,
            value,
            catalogue,
            currentIndex,
            info,
            infoData,
        };
    },
};
</script>

<style lang="less" scoped>
.van-cell {
    box-shadow:
        12.5px 12.5px 10px rgba(0, 0, 0, 0.09),
        100px 100px 80px rgba(0, 0, 0, 0.18);
}

hr {
    box-shadow: inset 0px 2px 4px #0000003F;
    width: 355px;
    margin-left: 10px;
}

.histry {
    height: 30px;
    background: #C0DF7C72;
    margin-top: 8.5px;
    border-radius: 0 10px 10px 0;
    width: 370px;
    display: flex;
    align-items: center;
    position: relative;

    span {
        font-size: 14px;
        font-weight: 500;
        line-height: 20.12px;
        color: rgba(56, 56, 56, 1);
        position: absolute;
        left: 4px;
    }

    img {
        position: absolute;
        width: 24px;
        right: 6.5px;
    }
}

.content {
    display: flex;
    width: 100%;
    height: calc(100vh - 50px - 54px - 30px - 9px);

    .left-catalogue {
        width: 100px;

        .catalogue {
            height: 60px;
            width: 100px;
            background-color: #A4BD6DFF;
            margin-top: 14px;
            border-radius: 0 55px 55px 0;
            box-shadow: 0px 1px 2px;
            position: relative;
            box-shadow: 0px 2px 4px #0000003F, 0px 2px 4px #0000003F;

            .catalogue-title {
                height: 54px;
                width: 94px;
                background-color: #fff;
                position: absolute;
                top: 3px;
                left: 2px;
                border-radius: 0 55px 55px 0;
                display: flex;
                align-items: center;
                justify-content: center;

                span {
                    font-size: 16px;
                    font-weight: 600;
                    line-height: 22.99px;
                    color: rgba(0, 0, 0, 1);
                    text-align: center;
                    vertical-align: top;
                }

                &.selected {
                    background-color: #C0DF7CFF;
                    box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
                }
            }
        }
    }

    .right-content {
        flex: 1;
        border-radius: 12px 0 0 12px;
        background-color: #fff;
        box-sizing: border-box;
        touch-action: auto;
        overflow-y: hidden;
        height: 98%;
    }
}
</style>